/* GUI CONVERTED from rqrqup.p (converter v1.75) Sat Aug 12 23:13:20 2000 */
/* rqrqup.p   - REQUISITION DELETE/ARCHIVE                                */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                    */
/* All rights reserved worldwide.  This is an unpublished work.           */
/*V8:ConvertMode=FullGUIReport                                            */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                   */
/* REVISION: 8.5      LAST MODIFIED: 05/05/97   BY: *J1Q2* B. Gates       */
/* REVISION: 8.5      LAST MODIFIED: 10/23/97   BY: *J243* Patrick Rowan  */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane      */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan     */
/* REVISION: 8.6E     LAST MODIFIED: 07/22/98   BY: *L040* Brenda Milton  */
/* REVISION: 8.6E     LAST MODIFIED: 08/17/98   BY: *J2SV* Dana Tunstall  */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb              */


/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

         {mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rqrqup_p_1 "Requisition Date"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqup_p_2 "Requisition History"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqup_p_3 "History Older Than Days"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqup_p_4 "Delete"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqup_p_5 "Archive"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqup_p_6 "Archive File"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

/*L040*/ /* THIS IS NECESSARY FOR FULL GUI REPORTS */
/*L040*/ {gprunpdf.i "mcpl" "p"}

         define variable nbr like rqm_mstr.rqm_nbr.
         define variable nbr1 like rqm_mstr.rqm_nbr.
         define variable req_by like rqm_rqby_userid.
         define variable req_by1 like rqm_rqby_userid.
         define variable end_user like rqm_end_userid.
         define variable end_user1 like rqm_end_userid.
         define variable site like rqm_site.
         define variable site1 like rqm_site.
         define variable sub like rqm_sub.
         define variable sub1 like rqm_sub.
         define variable cc like rqm_cc.
         define variable cc1 like rqm_cc.
         define variable job like rqm_job.
         define variable job1 like rqm_job.
         define variable entity like rqm_entity.
         define variable entity1 like rqm_entity.
         define variable reqdate like rqm_req_date.
         define variable reqdate1 like rqm_req_date.
         define variable history_older_than_days as integer
            label {&rqrqup_p_3}.
         define variable rdelete like mfc_logical label {&rqrqup_p_4}.
         define variable archive like mfc_logical label {&rqrqup_p_5}.
         define variable filename as character format "x(12)"
            label {&rqrqup_p_6}.
         define variable hst_line_header as character
            label {&rqrqup_p_2}.

         define variable qty_open as decimal no-undo.
         define variable requm like rqd_um no-undo.
         
         
         define stream history.

         
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
            
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
nbr             colon 20
            nbr1            colon 50 label {t001.i}
            req_by          colon 20
            req_by1         colon 50 label {t001.i}
            end_user        colon 20
            end_user1       colon 50 label {t001.i}
            site            colon 20
            site1           colon 50 label {t001.i}
            sub             colon 20
            sub1            colon 50 label {t001.i}
            cc              colon 20
            cc1             colon 50 label {t001.i}
            job             colon 20
            job1            colon 50 label {t001.i}
            entity          colon 20
            entity1         colon 50 label {t001.i}
            reqdate         colon 20 label {&rqrqup_p_1}
            reqdate1        colon 50 label {t001.i}
            skip(1)
            history_older_than_days colon 35
            skip(1)
            rdelete         colon 15
            archive         colon 15
            filename        colon 15
          SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



         /* SET EXTERNAL LABELS */
         setFrameLabels(frame a:handle).

         FORM /*GUI*/ 
         with STREAM-IO /*GUI*/  frame rptline width 132 down.

         FORM /*GUI*/ 
            rqh_nbr
         with STREAM-IO /*GUI*/  frame hstline width 132 down.

         /* SET EXTERNAL LABELS */
         setFrameLabels(frame hstline:handle).

         
/*GUI*/ {mfguirpa.i false  "printer" 132 }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:

            output stream history close.

            if nbr1 = hi_char then nbr1 = "".
            if req_by1 = hi_char then req_by1 = "".
            if end_user1 = hi_char then end_user1 = "".
            if site1 = hi_char then site1 = "".
            if sub1 = hi_char then sub1 = "".
            if cc1 = hi_char then cc1 = "".
            if job1 = hi_char then job1 = "".
            if entity1 = hi_char then entity1 = "".
            if reqdate = low_date then reqdate = ?.
            if reqdate1 = hi_date then reqdate1 = ?.

            
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


            if rdelete then do:
               if archive then do:
/*L040*/          assign
/*J2SV** BEGIN DELETE **
 *         filename = string(today,"999999").
 *         filename = "po" + substring(filename,5,2)
 *              + substring(filename,1,2)
 *              + substring(filename,3,2).
 *         filename = filename + ".hst".
 *J2SV** END DELETE **/

/*J2SV*/      filename = "po"
/*J2SV*/                 + substring(string(year(today),"9999"),3,2)
/*J2SV*/                 + string(month(today),"99")
/*J2SV*/                 + string(day(today),"99")
/*J2SV*/                 + ".hst".

                     filename = filename + ".hst".
                  display filename with frame a.
                  {mfmsg.i 51 1}
                  /* Note: archive files should be backed up and deleted *
                   * from disk */

                  if search(filename) <> ? then do:
                     {mfmsg03.i 52 2 filename """" """"}
                     /* WARNING: <filename> exists, archive data will be *
                      * appended */
                  end.

                  output stream history to value(filename) append.
               end.
               else do:
                  display "" @ filename with frame a.
               end.
            end.
            else do:
               display "" @ filename with frame a.

               if archive then do:
                 {mfmsg.i 7739 3} /* CANNOT ARCHIVE UNLESS DELETE = YES */
                 /*GUI UNDO removed */ RETURN ERROR.
               end.
            end.

            if nbr1 = "" then nbr1 = hi_char.
            if req_by1 = "" then req_by1 = hi_char.
            if end_user1 = "" then end_user1 = hi_char.
            if site1 = "" then site1 = hi_char.
            if sub1 = "" then sub1 = hi_char.
            if cc1 = "" then cc1 = hi_char.
            if job1 = "" then job1 = hi_char.
            if entity1 = "" then entity1 = hi_char.
            if reqdate = ? then reqdate = low_date.
            if reqdate1 = ? then reqdate1 = hi_date.

            /* SELECT PRINTER */
            
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i  "printer" 132}
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:

define buffer rqmmstr for rqm_mstr.
define buffer rqhhist for rqh_hist.


            {mfphead.i}

            rqmloop:
            for each rqm_mstr no-lock
            where rqm_nbr >= nbr and rqm_nbr <= nbr1
            and rqm_rqby_userid >= req_by and rqm_rqby_userid <= req_by1
            and rqm_end_userid >= end_user and rqm_end_userid <= end_user1
            and rqm_site >= site and rqm_site <= site1
            and rqm_sub >= sub and rqm_sub <= sub1
            and rqm_cc >= cc and rqm_cc <= cc1
            and rqm_job >= job and rqm_job <= job1
            and rqm_entity >= entity and rqm_entity < entity1
            and rqm_req_date >= reqdate and rqm_req_date <= reqdate1:
               /* SEE IF ANY OPEN QUANTITIES
                * IF SO, NOT A CANDIDATE FOR DELETE/ARCHIVE*/

               for each rqd_det no-lock
               where rqd_nbr = rqm_nbr
               and rqd_status = "":
                  {gprun.i ""rqoqty.p""
                    "(input false, input rqd_site,
                      input rqd_nbr, input rqd_line,
                      output qty_open, output requm)"}

                  if qty_open <> 0 then next rqmloop.
               end.

               /* SEE IF ANY OPEN PO'S
                * IF SO, NOT A CANDIDATE FOR DELETE/ARCHIVE*/

               for each rqpo_ref no-lock
               where rqpo_req_nbr = rqm_nbr
               break by rqpo_po_nbr:
                  if first-of(rqpo_po_nbr) then do:
                     find po_mstr where po_nbr = rqpo_po_nbr
                     no-lock no-error.

                     if available po_mstr
                     and not (po_stat = "C" or po_stat = "X")
                        then next rqmloop.
                  end.
               end.

               /* DISPLAY REQ HEADER BASICS */

               /* SET EXTERNAL LABELS */
               setFrameLabels(frame rptline:handle).
               display
                  rqm_nbr
                  rqm_rqby_userid
                  rqm_end_userid
                  rqm_site
                  rqm_sub
                  rqm_cc
                  rqm_job
                  rqm_entity
                  rqm_req_date
               with frame rptline STREAM-IO /*GUI*/ .

               down 1 with frame rptline.

               /* DELETE/ARCHIVE... */

               if rdelete then do:
                  /* ...THE APPROVAL RECORDS */

                  for each rqda_det exclusive-lock
                  where rqda_nbr = rqm_nbr:
                     if archive then do:
                        export stream history "rqda_det".
                        export stream history rqda_det.
                     end.

                     delete rqda_det.
                  end.

                  /* ...THE REQ-PO CROSSREFERENCE RECORDS */

                  for each rqpo_ref exclusive-lock
                  where rqpo_req_nbr = rqm_nbr:
                     if archive then do:
                        export stream history "rqpo_ref".
                        export stream history rqpo_ref.
                     end.

                     delete rqpo_ref.
                  end.

                  /* ...THE REQ LINE RECORDS */

                  for each rqd_det exclusive-lock
                  where rqd_nbr = rqm_nbr:
                     if archive then do:
                        export stream history "rqd_det".
                        export stream history rqd_det.
                     end.

                     delete rqd_det.
                  end.

                  /* ...THE REQ HEADER RECORD */

                  do for rqmmstr:
                     find rqmmstr where recid(rqmmstr) = recid(rqm_mstr)
                     exclusive-lock.

                     if archive then do:
                        export stream history "rqm_mstr".
                        export stream history rqm_mstr.
/*L040*/                /* ARCHIVE THE EXRU_USAGE RECORDS */
/*L040*/                output stream history close.
/*L040*/                {gprunp.i "mcpl" "p" "mc-archive-ex-rate-usage"
                          "(input rqmmstr.rqm_exru_seq,
                            input filename)"}
/*L040*/                output stream history to value(filename) append.
                     end.

/*L040*/             /* DELETE THE EXRU_USAGE RECORDS */
/*L040*/             {gprunp.i "mcpl" "p" "mc-delete-ex-rate-usage"
                       "(input rqmmstr.rqm_exru_seq)"}

                     delete rqmmstr.
                  end.
               end.
            end.  /* rqmloop */

            /* DELETE HISTORY */

            find first rqh_hist
            where not can-find(rqm_mstr where rqm_nbr = rqh_nbr)
            and today - rqh_date > history_older_than_days
            no-lock no-error.

            if available (rqh_hist) then do:
               page.
             do with frame a1:
           /* SET EXTERNAL LABELS */
               setFrameLabels(frame a1:handle).
               display hst_line_header
               with frame a1 side-labels width 132 STREAM-IO /*GUI*/ .
             end. /* do with */

               for each rqh_hist no-lock
               where not can-find(rqm_mstr where rqm_nbr = rqh_nbr)
               and today - rqh_date > history_older_than_days
               break by rqh_nbr:

                  if first-of (rqh_nbr) then do:
                     /* DISPLAY REQ HISTORY BASICS */

                     display
                        rqh_nbr
                     with frame hstline STREAM-IO /*GUI*/ .

                     down 1 with frame hstline.
                  end.  /* if first-of rqh_hist */

                  if rdelete then do:
                      do for rqhhist:
                         find rqhhist where recid(rqhhist) = recid(rqh_hist)
                         exclusive-lock.

                         if archive then do:
                            export stream history "rqh_hist".
                            export stream history rqh_hist.
                         end.

                         delete rqhhist.

                      end.
                  end.  /* if rdelete */
               end. /* for each rqh_hist */
            end.

            output stream history close.
            
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

         end.  /* repeat */

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" nbr nbr1 req_by req_by1 end_user end_user1 site site1 sub sub1 cc cc1 job job1 entity entity1 reqdate reqdate1 history_older_than_days rdelete archive "} /*Drive the Report*/
